//
//  CourseDetailViewController.m
//  Arts1
//
//  Created by 孤星晨宇 on 15/9/15.
//  Copyright (c) 2015年 Arts1. All rights reserved.
//

#import "CourseDetailViewController.h"
#import "INtroduceCourseTableViewController.h"
#import <MediaPlayer/MediaPlayer.h>

#import "AllHeader.h"
#import "CourseViewController.h"
#import "CourseDetailModel.h"
/// 微信分享
#import "ShareViewController.h"
#import <UIImageView+WebCache.h>

//  支付动画
#import "PayAnimationViewController.h"
#import "PayVC.h"
#import "MovieViewController.h"





// 课程详情
//#define  cDURL @"http://arts1.dlab.com.cn/app/courseinfo"
#define  cDURL @"http://arts1.cn/app/courseinfo"

// 点赞
//#define goodURL @"http://arts1.dlab.com.cn/app/zan"
#define goodURL @"http://arts1.cn/app/zan"

 // 视频收藏
//#define  storeURL @"http://arts1.dlab.com.cn/app/collectvideo"
#define  storeURL @"http://arts1.cn/app/collectvideo"

//  创建订单
#define  oderURL @"http://www.arts1.cn/app/order"

@interface CourseDetailViewController ()



// 视频播放器
@property (nonatomic, strong) UIView *playView;
@property (nonatomic, strong) MovieViewController *moviePlayerVC;
@property (nonatomic, strong) UIButton *playButton;

// 课程介绍
@property (nonatomic, strong) UIButton *leftBTN;

// 视频详情
@property (nonatomic, strong) UIButton *rightBTN;

// tabbar上的遮盖视图
@property (nonatomic, strong) UIView *bottomView;

// 视图底部的tabbar按钮
@property (nonatomic, strong) UIButton *tabBarBTN;

// 课程介绍页面
@property (nonatomic, strong) INtroduceCourseTableViewController *courseIVC;

// 分享选项页面
@property (nonatomic, strong) ShareViewController *shareVC;

// model类
@property (nonatomic, strong) CourseDetailModel *course;

// 视频播放 url
@property (nonatomic, strong) NSString *url;

// 播放器展位图
@property (nonatomic, strong) UIImageView *imageView;

// 生成渐变层
@property (strong, nonatomic) CAGradientLayer *gradientLayer;

// 支付动画
@property (nonatomic, strong) PayAnimationViewController *payAnimationVC;
@property (nonatomic, strong) UIButton *removePayViewButton;
@property (nonatomic, strong) UIButton *payButton;
@property (nonatomic, strong) NSDictionary *oderDic;    //  订单



@end

@implementation CourseDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    
    [self requestData];
    
    [self createNavigationBar];
    [self createPlayView];
    [self createCourseIntroduceview];
    [self createButtons];
    [self createTabBarView];
//    [self createShareView];
}

#pragma mark -自定义navigationbar
- (void)createNavigationBar{
    _navigationview = [[CourseDetailHeadView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, 44)];
    _navigationview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_navigationview];
    //  给返回按钮添加点击事件
    [_navigationview.backButton addTarget:self action:@selector(backCourse) forControlEvents:(UIControlEventTouchUpInside)];
    //  给分享按钮添加点击事件
    [_navigationview.shareBTN addTarget:self action:@selector(tapToVIPAnimation) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark -网络请求
- (void)requestData{
        AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
        manage.responseSerializer.acceptableContentTypes  =[NSSet setWithObject:@"text/html"];
        manage.responseSerializer = [AFHTTPResponseSerializer serializer];
        
    NSDictionary *userDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataForKeyAndUid"];
    NSString *uid = userDic[@"data"][@"uid"];
    NSString *key = userDic[@"data"][@"key"];
    
    //请求参数
   NSDictionary *pardic = @{@"courseId":_model.Id,@"uid":uid,@"key":key};
    
    NSLog(@"uid === %@ ***** key %@",uid, key);
    
        [manage POST:cDURL parameters:pardic
             success:^(AFHTTPRequestOperation *operation, id responseObject)
         {
             // 请求成功的时候调用这个block
             NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
             //返回的状态
             int index = [dic[@"status"] intValue];
             if (index == 1) {
                 NSDictionary *dict = dic[@"data"];
                 _course = [[CourseDetailModel alloc] init];
                 [_course setValuesForKeysWithDictionary:dict];
             }
             
             NSLog(@"视频详情*****返回数据 ： %@", dic);
             // 判断是否有观看权限 isAllow
             dispatch_async(dispatch_get_main_queue(), ^{
                 _navigationview.course = _course;
                 _courseIVC.detail = _course;
                 
                 if ([_course.isAllow intValue]) {
                     
                     [self addImageViewForPlayView];
                     [_bottomView removeFromSuperview];
                     [_playButton addTarget:self action:@selector(presentMovieController) forControlEvents:(UIControlEventTouchUpInside)];
                     NSLog(@"看有没有加上动作0000");
                     [self.view addSubview:_playButton];
                 } else {
                     [self addImageViewForPlayView];
                     [_playButton addTarget:self action:@selector(showNoInformation) forControlEvents:(UIControlEventTouchUpInside)];
                     NSLog(@"看有没有加上动作1111");
                     [self.view addSubview:_playButton];
                 }
             });
             
         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             // 请求失败的时候调用调用这个block
             NSLog(@"请求失败");
         }];
}

- (void)showNoInformation{
    [MBProgressHUD show:@"您还没有权限视频观看" icon:nil view:self.view];
}


#pragma mark -addURLToPlay-判断用户是否具有播放权限
//  用户具有视频播放权限之后,给视频播放器添加url
- (void)addURLToPlay{
    _url = [_course.videoUrl componentsSeparatedByString:@"?"][0];
    _moviePlayerVC.moviePlayer.contentURL = [NSURL URLWithString:[_url stringByAppendingString:@"?"]];
}

 // 用户不具有视频播放权限之后,给视频播放器添加背景图片
- (void)addImageViewForPlayView{
    
    NSLog(@"看有没有加上动作2222");
    _url = nil;
    _imageView = [[UIImageView alloc] initWithFrame:_playView.bounds];
    _imageView.backgroundColor = [UIColor blackColor];
    [_imageView setContentMode:(UIViewContentModeScaleAspectFill)];
    _imageView.layer.masksToBounds = YES;
    _imageView.alpha = 0.8;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:_course.photo] placeholderImage:nil options:(SDWebImageRetryFailed | SDWebImageLowPriority)];
    [_playView addSubview:_imageView];
}

#pragma mark  - 视频播放
- (void)createPlayView{

    _playView = [[UIImageView alloc] init];
    _playView.backgroundColor = [UIColor blackColor];
    _playView.frame = CGRectMake(0, _navigationview.bottom, SCREEN_WIDTH, 201 * HEIGHT);
    
    _playButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _playButton.frame = CGRectMake(SCREEN_WIDTH / 2 - 32, _playView.size.height / 2 - 33 + _navigationview.bottom, 66, 64);
    [_playButton setImage:[UIImage imageNamed:@"playButton"] forState:(UIControlStateNormal)];
    _playButton.alpha = 0.8;
    
    
    [self.view addSubview:_playView];
}

- (void)presentMovieController{
    _url = [_course.videoUrl componentsSeparatedByString:@"?"][0];
    _moviePlayerVC = [[MovieViewController alloc] initWithContentURL:[NSURL URLWithString:[_url stringByAppendingString:@"?"]]];
    
//    _moviePlayerVC = [[MovieViewController alloc] init];
    [_moviePlayerVC.moviePlayer prepareToPlay];
    [self presentMoviePlayerViewControllerAnimated:_moviePlayerVC];
    
    [_moviePlayerVC.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
    
    [_moviePlayerVC.view setBackgroundColor:[UIColor clearColor]];
    
    [_moviePlayerVC.view setFrame:self.view.bounds];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                            selector:@selector(myMovieFinishedCallback:)
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:_moviePlayerVC.moviePlayer];
}

-(void)myMovieFinishedCallback:(NSNotification*)aNotification{
    MovieViewController* theMovie = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
//    [self dismissMoviePlayerViewControllerAnimated];
}


// 后退
- (void)backCourse
{
    self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark  - 分享-暂时不用
// 创建分享选项卡
- (void)createShareView{
    _shareVC = [[ShareViewController alloc] init];
    [self.view addSubview:_shareVC.view];
    _shareVC.view.frame = CGRectMake(0,SCREEN_HEIGHT,SCREEN_WIDTH,SCREEN_HEIGHT);
}

// 分享
- (void)shareMessage:(UIButton *)btn{
    [UIView animateWithDuration:0.25 delay:0 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
        _shareVC.view.frame = CGRectMake(0,0,SCREEN_WIDTH,SCREEN_HEIGHT);
    } completion:^(BOOL finished) {
        
    }];
}


#pragma mark  - 课程介绍、视屏详情
- (void)createButtons{
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, _playView.bottom, SCREEN_WIDTH, 40)];
    whiteView.backgroundColor = [UIColor whiteColor];
    [UIView viewWideForShadowColor:whiteView];
//    [UIView viewShadowColor:whiteView];
    
    // 下载
    _leftBTN = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _leftBTN.frame = CGRectMake(0, 0, whiteView.width / 2.0 - 0.5, whiteView.height);
    if (_model.iscollect) {
       [_leftBTN setTitle:@"取消收藏" forState:(UIControlStateNormal)];
    } else {
    [_leftBTN setTitle:@"收藏" forState:(UIControlStateNormal)];
    }
    _leftBTN.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [_leftBTN setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
    [_leftBTN addTarget:self action:@selector(introduceCourse:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteView addSubview:_leftBTN];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(whiteView.width / 2.0 - 0.25, 7, 0.5, 26)];
    line.backgroundColor = kCustomColor(150, 150, 150, 0.5);
    [whiteView addSubview:line];
    
    // 称赞
    _rightBTN = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _rightBTN.frame = CGRectMake(_leftBTN.right + 1, 0, whiteView.width / 2.0 - 0.5, whiteView.height);
    [_rightBTN setTitleColor:sFONTCOLOR forState:(UIControlStateNormal)];
    [_rightBTN setTitle:@"称赞" forState:(UIControlStateNormal)];
    _rightBTN.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:14];
    [_rightBTN addTarget:self action:@selector(introduceMedia:) forControlEvents:(UIControlEventTouchUpInside)];
    [whiteView addSubview:_rightBTN];
    
    [self.view addSubview:whiteView];
}

#pragma mark  - 视频收藏
- (void)introduceCourse:(UIButton *)btn{

    int collect = [_model.iscollect intValue];
    if (collect) {
        [_leftBTN setTitle:@"取消收藏" forState:(UIControlStateNormal)];
    } else {
        [_leftBTN setTitle:@"收藏" forState:(UIControlStateNormal)];
    }
      [self storeCourseVideo];
}
/**
 *  视频收藏  ---  视频详情
 */
- (void)storeCourseVideo{
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *userDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataForKeyAndUid"];
    
    //请求参数
    NSDictionary *pardic = @{@"key":userDic[@"data"][@"key"],@"uid":userDic[@"data"][@"uid"],@"courseId":_model.Id};
    
    [manage POST:storeURL parameters:pardic
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
            // 请求成功的时候调用这个block
            NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
            // 请求返回的状态，当status = 1 时有数据
            NSInteger status = [dic[@"status"] integerValue];
            
            NSString *str = nil;
                switch (status) {
                    case 1:{
                        str = @"收藏成功";
                        _model.iscollect = dic[@"iscollect"];
                        [MBProgressHUD show:@"收藏成功" icon:nil view:self.view];
                    }
                        break;
                    case 0:
                        str = @"没有视频信息";
                        break;
                    case -1:
                        str = @"未登录";
                        break;
                    case -2:
                        str = @"用户名或密码错误";
                        break;
                    case -3:
                        str = @"参数不正确";
                        break;
                    default:
                        break;
            }

        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            // 请求失败的时候调用调用这个block
            NSLog(@"请求失败");
        }];


}


#pragma mark  - 称赞
- (void)introduceMedia:(UIButton *)btn{
    [self requestGoodDataAndStatus];
}

//  视频点赞，网络请求
- (void)requestGoodDataAndStatus{
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *pardic = @{@"id":_model.Id,@"type":@"course"};
    
    [manage GET:goodURL parameters:pardic
        success:^(AFHTTPRequestOperation *operation, id responseObject) {
            // 请求成功的时候调用这个block
            NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
            // 请求返回的状态，当status = 1 时有数据
            NSInteger status = [dic[@"status"] integerValue];
            if (status == 1) {
                //信息提示框
                [MBProgressHUD show:@"谢谢欣赏" icon:nil view:self.view];
            }
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            // 请求失败的时候调用调用这个block
            NSLog(@"请求失败");
        }];
    
}

#pragma mark  - 视频介绍页面
- (void)createCourseIntroduceview{
    
    _courseIVC = [[INtroduceCourseTableViewController alloc] init];
    [self addChildViewController:_courseIVC];
    _courseIVC.view.frame = CGRectMake(0 , _playView.bottom + 40 , SCREEN_WIDTH, SCREEN_HEIGHT - _playView.bottom - 40);
    [_courseIVC.tableView setContentInset:(UIEdgeInsetsMake(6, 0, 0, 0))];
    _courseIVC.view.backgroundColor = kBackgroundColor;
    _courseIVC.tableView.frame = CGRectMake(0 , _playView.bottom + 40 , _courseIVC.view.size.width,  SCREEN_HEIGHT - _playView.bottom - 40);
    
    _payAnimationVC.price = _course.price;
    _payAnimationVC.courseName = _course.title;
    
    [self.view addSubview:_courseIVC.view];
    
}

//  创建tabbarview视图
- (void)createTabBarView{
    // tabbar上面的遮盖视图
    _bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49, SCREEN_WIDTH, 49)];
    _bottomView.backgroundColor = lFONTCOLOR;
    
    // 播放页面底部的 “支持｜更多” 按钮
    _tabBarBTN = [UIButton buttonWithType:(UIButtonTypeCustom)];
    _tabBarBTN.frame = CGRectMake(SCREEN_WIDTH/2.0 - 45, 9.5, 90, 30);
    _tabBarBTN.titleLabel.font = [UIFont systemFontOfSize:16];
    _tabBarBTN.backgroundColor = lFONTCOLOR;
    _tabBarBTN.tintColor = sFONTCOLOR;
    [_tabBarBTN setTitle:@"购买" forState:(UIControlStateNormal)];
//    [_tabBarBTN addTarget:self action:@selector(tapToVIP) forControlEvents:(UIControlEventTouchUpInside)];
    [_tabBarBTN addTarget:self action:@selector(requistOder) forControlEvents:(UIControlEventTouchUpInside)];
    [_bottomView addSubview:_tabBarBTN];
    [self.view addSubview:_bottomView];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark  - 进入支付页面
- (void)tapToPay{
    PayVC *payVC = [[PayVC alloc] init];
    payVC.oderDictionary = _oderDic;
    payVC.course = _course;
    
    __weak CourseDetailViewController *wCourseDVC = self;
    payVC.successpaylock = ^(){
    
        [wCourseDVC addURLToPlay];
        [wCourseDVC.imageView removeFromSuperview];
    
    };
    
    [self.navigationController pushViewController:payVC animated:YES];
    [self removePayAnimationView];
    
    NSLog(@"==== 进入支付页面 ====");
}

//取消当前页面
- (void)removePayAnimationView{
    [_payAnimationVC.view removeFromSuperview];
    [_payButton removeFromSuperview];
    [_removePayViewButton removeFromSuperview];
}

//  创建视频订单
- (void)requistOder{
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *userDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataForKeyAndUid"];
    
    //请求参数
    NSDictionary *pardic = @{@"key":userDic[@"data"][@"key"],@"uid":userDic[@"data"][@"uid"],@"id":_model.Id,@"type":@"course"};
//    NSDictionary *pardic = @{@"key":userDic[@"data"][@"key"],@"uid":userDic[@"data"][@"uid"],@"courseId":_model.Id};
    
    [manage POST:oderURL parameters:pardic
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             // 请求成功的时候调用这个block
             NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
             // 请求返回的状态，当status = 1 时有数据
             NSInteger status = [dic[@"status"] integerValue];
                          
             NSString *str = nil;
             switch (status) {
                 case 1:{
                     str = @"操作成功";
                     _oderDic = dic;
                     [self tapToPay];
                 }
                     break;
                 case 0:
                     str = @"未知错误";
                     break;
                 case -1:
                     str = @"用户名或密码为空";
                     break;
                 case -2:
                     str = @"用户名或密码错误";
                     break;
                 case -3:
                     str = @"类型不正确";
                     break;
                 case -4:
                     str = @"无法生成订单号";
                     break;
                 case -5:
                     str = @"未找到课程";
                     break;
                 case -6:
                     str = @"不能重复购买";
                     [MBProgressHUD show:@"您已购买，无需重复购买" icon:nil view:self.view];
                     break;
                 default:
                     break;
             }
             
             
             
             NSLog(@" 创建订单  返回数据 ： %@ ",dic);
             
         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             // 请求失败的时候调用调用这个block
             NSLog(@"请求失败");
         }];
    
    
}

//  注册会员
- (void)tapToVIPAnimation{
    //  添加支付动画
    _payAnimationVC = [[PayAnimationViewController alloc] init];
    _payAnimationVC.price = @"199";
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = YES;
    [self.view addSubview:_payAnimationVC.view];
    
    _payButton = [UIButton buttonWithType:(UIButtonTypeRoundedRect)];
    _payButton.frame = CGRectMake(_payAnimationVC.backgroundView.size.width - 15 - 65 + 25, SCREEN_HEIGHT / 2 - 210 / 2 - 50 + _payAnimationVC.backgroundView.size.height - 17 - 37, 65, 37);;
    _payButton.layer.cornerRadius = 5;
    _payButton.layer.masksToBounds = YES;
    _payButton.alpha = 0;
    _payButton.backgroundColor = kCustomColor(245, 165, 35, 1);
    [_payButton setTitle:@"购买" forState:(UIControlStateNormal)];
    _payButton.titleLabel.font = [UIFont boldSystemFontOfSize:17];
    [_payButton setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    [_payButton addTarget:self action:@selector(requistVIPOder) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_payButton];
    
    [UIView animateWithDuration:0.1 delay:2.3 options:(UIViewAnimationOptionCurveEaseIn) animations:^{
        _payButton.alpha = 1;
    } completion:nil];
    
    _removePayViewButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _removePayViewButton.frame = CGRectMake(SCREEN_WIDTH / 2.0 - 20, SCREEN_HEIGHT - 100 *HEIGHT, 40, 40);
    _removePayViewButton.alpha = 0.3;
    [_removePayViewButton setBackgroundImage:[UIImage imageNamed:@"cancelcon"] forState:(UIControlStateNormal)];
    [_removePayViewButton addTarget:self action:@selector(removePayAnimationView) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:_removePayViewButton];
    
    
}

//  创建会员订单
- (void)requistVIPOder{
    AFHTTPRequestOperationManager *manage = [AFHTTPRequestOperationManager manager];
    
    manage.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    
    manage.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    NSDictionary *userDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataForKeyAndUid"];
    
    //请求参数
    NSDictionary *pardic = @{@"key":userDic[@"data"][@"key"],@"uid":userDic[@"data"][@"uid"],@"id":@0,@"type":@"vip"};
    //    NSDictionary *pardic = @{@"key":userDic[@"data"][@"key"],@"uid":userDic[@"data"][@"uid"],@"courseId":_model.Id};
    
    [manage POST:oderURL parameters:pardic
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             // 请求成功的时候调用这个block
             NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
             // 请求返回的状态，当status = 1 时有数据
             NSInteger status = [dic[@"status"] integerValue];
             
             NSString *str = nil;
             switch (status) {
                 case 1:{
                     str = @"操作成功";
                     _oderDic = dic;
                     [self tapToVIPPay];
                 }
                     break;
                 case 0:
                     str = @"未知错误";
                     break;
                 case -1:
                     str = @"用户名或密码为空";
                     break;
                 case -2:
                     str = @"用户名或密码错误";
                     break;
                 case -3:
                     str = @"类型不正确";
                     break;
                 case -4:
                     str = @"无法生成订单号";
                     break;
                 case -5:
                     str = @"未找到课程";
                     break;
                 case -6:
                     str = @"不能重复购买";
                     [MBProgressHUD show:@"您已购买，无需重复购买" icon:nil view:self.view];
                     break;
                 default:
                     break;
             }
             
             
             
             NSLog(@" 创建订单  返回数据 ： %@ ",dic);
             
         } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             // 请求失败的时候调用调用这个block
             NSLog(@"请求失败");
         }];
    
    
}

- (void)tapToVIPPay{
    PayVC *payVC = [[PayVC alloc] init];
    payVC.navigationController.title = @"在线支付";
    payVC.oderDictionary = _oderDic;
    
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:payVC animated:YES];
//    self.hidesBottomBarWhenPushed = NO;
    [self removePayAnimationView];
    
    __weak CourseDetailViewController *wCourseDVC = self;
    payVC.successpaylock = ^(){
        
        [wCourseDVC addURLToPlay];
        [wCourseDVC.imageView removeFromSuperview];
        
    };
    
    NSLog(@"==== 进入支付页面 ====");
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
